/* str.h : dgnsc string func
 * Copyright (C) 2009-2011 drangon <drangon.zhou@gmail.com>
 * 2011-09
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

#ifndef INCLUDED_DGNSC_STR_H
#define INCLUDED_DGNSC_STR_H

#ifdef __cplusplus
extern "C" {
#endif // __cplusplus

#define DGNSC_ATTR_PRINTF(x,y) __attribute__((format (printf,x,y)))

typedef struct dgn_str_st * dgn_str_t;

dgn_str_t dgn_str_init( int capacity );
dgn_str_t dgn_str_init_dup( const dgn_str_t str );
dgn_str_t dgn_str_init_c( const char * str, int len ); // len == -1 means total

void dgn_str_fini( dgn_str_t me );


// enlarge if need, return new capacity, may large than request
int dgn_str_reserve( dgn_str_t me, int capacity ); 
int dgn_str_len( const dgn_str_t me );
const char * dgn_str_c( const dgn_str_t me ); // never return NULL

// auto enlarge
const char * dgn_str_assign( dgn_str_t me, const dgn_str_t str );
// if str == NULL, then clear buffer
const char * dgn_str_assign_c( dgn_str_t me, const char * str, int len );
const char * dgn_str_append( dgn_str_t me, const dgn_str_t str );
const char * dgn_str_append_c( dgn_str_t me, const char * str, int len );
const char * dgn_str_assign_fmt( dgn_str_t me, const char * fmt, ... ) DGNSC_ATTR_PRINTF(2,3);
const char * dgn_str_append_fmt( dgn_str_t me, const char * fmt, ... ) DGNSC_ATTR_PRINTF(2,3);

int dgn_str_cmp( const dgn_str_t me, const dgn_str_t str );
int dgn_str_cmp_c( const dgn_str_t me, const char * str, int len );
int dgn_str_casecmp( const dgn_str_t me, const dgn_str_t str );
int dgn_str_casecmp_c( const dgn_str_t me, const char * str, int len );

#ifdef __cplusplus
}
#endif // __cplusplus

#endif // INCLUDED_DGNSC_STR_H

